package com.gitee.feizns.itrip.personal.utils.service;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author feizns
 * @since 2018/12/26 0026
 */
public abstract class AbstractService<T, M extends BaseMapper<T>> implements BaseService<T> {

    @Autowired
    protected M baseMapper;

    @Override
    public List<T> getAll(Page<T> page) {
        return baseMapper.selectPage(page, null);
    }

    @Override
    public T get(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public boolean add(T entity) {
        return baseMapper.insert(entity) > 0;
    }

    @Override
    public boolean upd(T entity) {
        return baseMapper.updateById(entity) > 0;
    }

    @Override
    public boolean del(Long id) {
        return baseMapper.deleteById(id) > 0;
    }

    @Override
    public int count() {
        return baseMapper.selectCount(null);
    }

}
